#pragma once 
#include<iostream>
#include<string>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>


#define Mode 0666
#define Path "./fifo"
using namespace std;
class Fifo
{
    public:
        Fifo(const string& path)
        :_path(path)
        {
            umask(0);
            int n = mkfifo(_path.c_str(),Mode); //创建命名管道：本质就是创建文件文件
            if(n == 0)
            {
              cout<<"mkfifo success "<<endl;
            }
            else 
            {
              cerr<<"mkfifo failed, errno: " <<errno << ", string : "<<strerror(errno)<<std::endl;
            } 
        }
        ~Fifo()
        {
            int n = unlink(_path.c_str());
            if(n == 0)
            {
                cout << "remove fifo file " << _path << " success" << endl;
            }
            else 
            {
                cerr << "remove failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
            }
        }
    private:
        string _path;//文件路径+文件名
};
